import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)


export default new Vuex.Store({
    state: {
        goodsList:[],
    },
    mutations: {
        changeGoodsList(state, data) {
            for (let obj of data) {
                for (let child of obj.foods) {
                    child.num=0
                }
            }
            state.goodsList=data
        },

        //改变购物车数量
        changeShopCartNum(state,data) {
            for (let obj of state.goodsList) {
                for (let child of obj.foods) {
                    if (child.id === Number(data.id)) {
                        child.num+=data.num
                    }
                }
            }
        },

        //清空购物车，让所有num等于0
        emptyShopCart(state) {
            for (let obj of state.goodsList) {
                for (let child of obj.foods) {
                    child.num=0
                }
            }
        }
    }
})